<!--订单支付管理-->
<template>
  <div id="businessOrderPaymentRecord" class="app-container">
    <!--搜索条件-->
    <div class="filter-container">
      <el-form :model="listQuery" :inline="true">
        <el-form-item label="订单号">
          <el-input v-model="listQuery.orderNo" clearable placeholder="请输入订单号" @keyup.enter.native="handleFilter" />
        </el-form-item>
        <el-form-item label="交易单号">
          <el-input v-model="listQuery.tradeNo" clearable placeholder="请输入交易单号" @keyup.enter.native="handleFilter" />
        </el-form-item>
        <el-form-item label="支付时间">
          <el-date-picker
            v-model="payTimes"
            type="daterange"
            align="right"
            unlink-panels
            value-format="timestamp"
            range-separator="至"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
            :picker-options="pickerOptions" />
        </el-form-item>
        <el-form-item>
          <el-button type="primary" icon="el-icon-search" plain @click="handleFilter">搜索</el-button>
          <el-button icon="el-icon-refresh" plain @click="handleReset">重置</el-button>
        </el-form-item>
      </el-form>
    </div>

    <!--列表-->
    <div class="table-container flex-main">
      <div class="table-container-header">
        <table-toolbar :create="false" :remove="false" @refresh="handleFilter">
          <template slot="rightTool" />
        </table-toolbar>
      </div>
      <el-table
        ref="multipleTable"
        :data="list"
        header-cell-class-name="table-header"
        fit
        height="100%"
        highlight-current-row
        @selection-change="handleSelectionChange"
        @row-click="handleRowClick"
        @sort-change="sortChange"
      >
        <el-table-column type="selection" width="60" />
        <el-table-column align="center" prop="id" label="#" width="60">
          <template slot-scope="scope">{{ scope.$index+1 }}</template>
        </el-table-column>
        <el-table-column label="订单号" prop="orderId" :show-overflow-tooltip="true" width="150" />
        <el-table-column label="交易号/支付时间" prop="tradeNo" :show-overflow-tooltip="true" width="240">
          <template slot-scope="scope">
            <div>{{ scope.row.tradeNo }}</div>
            <div class="color-default">{{ scope.row.payTime | formatDate('yyyy-MM-dd hh:mm:ss') }}</div>
          </template>
        </el-table-column>
        <el-table-column label="支付渠道/交易方式" prop="channelPayWay" :show-overflow-tooltip="true" width="150">
          <template slot-scope="scope">
            <div>{{ scope.row.channelPayWay }}</div>
            <div class="color-default">{{ scope.row.tradeType }}</div>
          </template>
        </el-table-column>
        <el-table-column prop="grandTotal" sortable label="总费用" width="120">
          <template slot-scope="scope"><span class="color-primary">￥{{ scope.row.totalFee }}</span></template>
        </el-table-column>
        <el-table-column prop="grandTotal" label="状态" width="100">
          <template slot-scope="scope">
            <span v-if="scope.row.payStatus===0" class="color-primary">付款成功</span>
            <span v-if="scope.row.payStatus===1" class="color-danger">付款失败</span>
          </template>
        </el-table-column>
        <el-table-column label="商户号/收款帐号" prop="partnerId" :show-overflow-tooltip="true" width="150">
          <template slot-scope="scope">
            <div>{{ scope.row.partnerId }}</div>
            <div class="color-default">{{ scope.row.account }}</div>
          </template>
        </el-table-column>
        <el-table-column label="买家/应用标识" prop="userId" :show-overflow-tooltip="true" width="220">
          <template slot-scope="scope">
            <div>{{ scope.row.userId }}</div>
            <div class="color-default">{{ scope.row.appId }}</div>
          </template>
        </el-table-column>
        <el-table-column label="交易概述" prop="subject" min-width="150" show-overflow-tooltip />
      </el-table>
    </div>
    <div class="pagination_handler">
      <pagination v-show="total>0" :total="total" :page.sync="listQuery.page" :limit.sync="listQuery.limit" @pagination="fetchData" />
    </div>
  </div>
</template>

<script>
export default {
  components: {},

  data() {
    return {
      pickerOptions: {
        shortcuts: [{
          text: '最近一周',
          onClick(picker) {
            const end = new Date()
            const start = new Date()
            start.setTime(start.getTime() - 3600 * 1000 * 24 * 7)
            picker.$emit('pick', [start, end])
          }
        }, {
          text: '最近一个月',
          onClick(picker) {
            const end = new Date()
            const start = new Date()
            start.setTime(start.getTime() - 3600 * 1000 * 24 * 30)
            picker.$emit('pick', [start, end])
          }
        }, {
          text: '最近三个月',
          onClick(picker) {
            const end = new Date()
            const start = new Date()
            start.setTime(start.getTime() - 3600 * 1000 * 24 * 90)
            picker.$emit('pick', [start, end])
          }
        }]
      },
      payTimes: [],
      list: [],
      total: 0,
      listQuery: {
        page: 1,
        limit: 20,
        orderNo: null,
        tradeNo: null,
        payTimeStart: null,
        payTimeEnd: null,
        sort: '-gmtCreated',
        orderStatus: '2'
      },
      multipleSelectionRecords: []
    }
  },
  created() {
    this.fetchData()
  },
  methods: {
    // 表格自带方法开始
    /* 全选/反选*/
    handleSelectionChange(val) {
      this.multipleSelectionRecords = val
    },
    /* 表格行数据单击*/
    handleRowClick(row) {
      this.$refs.multipleTable.toggleRowSelection(row)
    },
    /* 表格列排序*/
    sortChange(data) {
      const { prop, order } = data
      if (prop) {
        if (order === 'ascending') {
          this.listQuery.sort = '+' + prop
        } else {
          this.listQuery.sort = '-' + prop
        }
      } else {
        this.listQuery.sort = '-payTime'
      }
      this.handleFilter()
    },
    // 表格自带方法结束

    /* 搜索*/
    handleFilter() {
      this.listQuery = {
        ...this.listQuery,
        page: 1
      }
      this.fetchData()
    },
    /* 重置*/
    handleReset() {
      this.listQuery = {
        ...this.listQuery,
        page: 1,
        limit: this.common.PAGE_LIMIT_DEFAULT,
        orderNo: null,
        tradeNo: null,
        payTimeStart: null,
        payTimeEnd: null,
        sort: this.common.SORT_DEFAULT
      }
      this.payTimes = []
      this.$refs.multipleTable.clearFilter()
      this.$refs.multipleTable.clearSort()
      this.fetchData()
    },
    async fetchData() {
      if (this.payTimes.length === 2) {
        this.listQuery = {
          ...this.listQuery,
          payTimeStart: this.payTimes[0],
          payTimeEnd: this.payTimes[1]
        }
      }
      const response = await this.$store.dispatch('businessOrderPaymentRecordPage', this.listQuery)
      this.list = response.records
      this.total = response.total
    }
  }
}
</script>
<style lang="scss" scoped>
</style>
